package com.woniuxy.credit_loans.collection_zhang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.credit_loans.collection_zhang.dto.PageDto;
import com.woniuxy.credit_loans.collection_zhang.service.BorWarningService;
import com.woniuxy.credit_loans.collection_zhang.service.BorrowService;
import com.woniuxy.credit_loans.entity.Borrow;
import com.woniuxy.credit_loans.entity.Borwarning;
import com.woniuxy.credit_loans.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("BorWarning")
public class BorWarningController {

    @Autowired
    private BorWarningService borWarningService;

    @PostMapping("/page")
    private Result selectAll(@RequestBody PageDto pageDto){
        PageHelper.startPage(pageDto.getCurrentPage(),pageDto.getPagesize(),true);

        List<Borwarning> list = borWarningService.selectAll(pageDto.getInput());
        PageInfo<Borwarning> pageInfo = new PageInfo<Borwarning>(list);

        return  Result.ok().data("list",list).data("pageInfo",pageInfo.getTotal());
    }

    @PostMapping("")
    private  Result add(@RequestBody Borwarning borwarning){
         int i = borWarningService.insertSelective(borwarning);
        if (i==0) {
            return  Result.ok();
        }else {
            return  Result.error();
        }
    }

    @GetMapping("{id}")
    private  Result selectByid(@PathVariable Long id){
         Borwarning borwarning = borWarningService.selectByPrimaryKey(id);
        return  Result.ok().data("borwarning",borwarning);
    }

    @PutMapping("")
    private  Result update(@RequestBody Borwarning borwarning){
        int i = borWarningService.updateByPrimaryKeySelective(borwarning);
        if (i==0) {
            return  Result.ok();
        }else {
            return  Result.error();
        }
    }
    @DeleteMapping("{id}")
    private  Result delete(@PathVariable Long id){
         int i = borWarningService.deleteByPrimaryKey(id);
        if (i==0) {
            return  Result.ok();
        }else {
            return  Result.error();
        }
    }
}
